/**
 * 登录页面
 */
layui.use(['layer', 'form'], function () {
    var layer = layui.layer;
    var form = layui.form;
    form.verify({
        username: function (value) {
            if (value.length == 0 || value.trim() == '' || value == null) {
                return '请输入用户名';
            }
        },
        password: function (value) {
            if (value.length == 0 || value.trim() == '' || value == null) {
                return '请输入密码';
            }
        }
    });
    form.on('submit(login)', function (data) {
        if (data.field.userIdentity == 'on') {
            data.field.userIdentity = "normal";
        } else {
            data.field.userIdentity = "super";
        }
        console.log(data.field);
        $.ajax({
            type: 'post',
            url: '/login/checkLogin',
            contentType: 'application/json',
            data: JSON.stringify(data.field),
            success: function (data) {
                if (data == "success") {
                    layer.msg("登录成功！");
                    location.href="/index/index";
                } else {
                    layer.msg("用户名或密码或Identity错误！");
                }
            },
            error: function (error) {
                layer.msg('404,error');
            }
        });
        return false;
    });
});